<?php
/**
 * В этом файле описываются сигналы, url и подключения (слоты) за которые отвечает AGPsource Core Platform 
 */

class Platform_connectManager
{
	//array of signals namespace
	static $prefix = array('sys_', 'test_'); 
	
	
	/**
	 * Возвращает массив роутинга URL на сигналы для подключения к основному.
	 * @return Array 
	 */
	static public function exportRouting()
	{
		return Array(
			//тестирование системы (можно убрать)
			'test/ok' => array('test_signal_OK'), 
			'test/failure' => array('test_signal_Failure')		
		);
	}
	
	
	//только одна функция, которая определяет, кто из игровых дочерних классов отвечает за сигнал	
	static public function signalManager($signal = null, $router = null )
	{
		if ( (empty($signal)) || (empty($router)) || (!is_object($router)) ) return false;
		else
			{
				//допустим, у нас сигнал agp_test_signal
				// $router->connect($signal, $connector);
				// return true; //обязательно вернуть true если нашли сигнал и false, если нет
				switch ($signal) 
				{
					// сигнал 1
					case "test_sinal1":
						$router->connect($signal, 'test_for_signa2');
						break;
					
					case "test_sinal2":
						$router->connect($signal, 'test_for_signal2');
						break;	
						
					case "test_sinalX":
						$router->connect($signal, 'test_for_signal2');
						break;
						
					case "test_signalN":
						$router->connect($signal, 'test_for_signal2');
						break;						
					
					
					
					//Системные сигналы
					case "sys_init":
						$router->connect($signal, array('AGPlatform_Core','_Platform_Init'));
						break;
					case "sys_pm_start":
						$router->connect($signal, array('AGPlatform_Core','_Platform_PerfomanceMeter_Start'));
						break;
					case "sys_pm_chekpoint":
						$router->connect($signal, array('AGPlatform_Core','_Platform_PerfomanceMeter_Checkpoint'));
						break;						
					case "sys_pm_stop":
						$router->connect($signal, array('AGPlatform_Core','_Platform_PerfomanceMeter_Stop'));
						break;
					case "sys_license_check":
						$router->connect($signal, array('AGPlatform_Core','_Platform_License_Check'));
						break;
					case "sys_session_start":
						$router->connect($signal, array('AGPlatform_Core','_Platform_Session_Start'));
						break;
					case "sys_requirments_check":
						$router->connect($signal, array('AGPlatform_Core','_Platform_Requirments_Check'));
						break;
					case "sys_security_ids_check":
						$router->connect($signal, array('AGPlatform_Core','_Platform_SecurityIDS_Check'));
						break;
					case "sys_templates":
						$router->connect($signal, array('AGPlatform_Core','_Platform_Template'));
						break;	
					case "sys_logs":
						$router->connect($signal, array('AGPlatform_Core','_Platform_Log'));
						break;	
					case "sys_fast_cache":
						$router->connect($signal, array('AGPlatform_Core','_Platform_FastCache'));
						break;	
					case "sys_file_cache":
						$router->connect($signal, array('AGPlatform_Core','_Platform_FileCache'));
						break;	
					case "sys_memcached_cache":
						$router->connect($signal, array('AGPlatform_Core','_Platform_Mem_Cache'));
						break;		
					case "sys_db":
						$router->connect($signal, array('AGPlatform_Core','_Platform_Db'));
						break;	
					case "sys_mail":
						$router->connect($signal, array('AGPlatform_Core','_Platform_Mail'));
						break;
					case "sys_acl":
						$router->connect($signal, array('AGPlatform_Core','_Platform_Acl'));
						break;	
					case "sys_acl_db":
						$router->connect($signal, array('AGPlatform_Core','_Platform_Acl_DB'));
						break;
					case "sys_recaptcha":
						$router->connect($signal, array('AGPlatform_Core','_Platform_Captcha_ReCaptcha'));
						break;	
					case "sys_redis":
						$router->connect($signal, array('AGPlatform_Core','_Platform_Redis'));
						break;	
					case "sys_time":
						$router->connect($signal, array('AGPlatform_Core','_Platform_TimeServer'));
						break;	
					case "sys_getbrowserinfo":
						$router->connect($signal, array('AGPlatform_Core','_Platform_GetClientBrowser_Info'));
						break;						
					case "sys_checkbrowserinfo":
						$router->connect($signal, array('AGPlatform_Core','_Platform_CheckClientBrowser'));
						break;						
					
					case "sys_output_start":
						$router->connect($signal, array('AGPlatform_Core','_Platform_Output_Start'));
						break;						
					case "sys_output_stop":
						$router->connect($signal, array('AGPlatform_Core','_Platform_Output_Stop'));
						break;		
						
					//отладчик и логгер PQP
					case "sys_pqp_start":
						$router->connect($signal, array('AGPlatform_Core','_Platform_PQP_Start'));
						break;	
					case "sys_pqp_stop":
						$router->connect($signal, array('AGPlatform_Core','_Platform_PQP_Stop'));
						break;	
					
					//сигналы локализации
					case "sys_locale_init":
						$router->connect($signal, array('AGPlatform_Core','_Platform_LocalesInit'));
						break;		
					case "sys_locale_set":
						$router->connect($signal, array('AGPlatform_Core','_Platform_LocalesSet'));
						break;		
						
						
							
					case "sys_exception":
						$router->connect($signal, array('AGPlatform_Core','_Platform_Exception'));
						break;	
						
						
						
					// тест
					case "test_signal_OK":
						$router->connect($signal, array('AGPlatform_Routing','testSignalOK'));
						break;
					
					case "test_signal_Failure":
						$router->connect($signal, array('AGPlatform_Routing','testSignalFailure'));
						break;
					
					//дефолтно, если нет обработчика сигналу
					default: throw new AGPlatform_Unknown_Signal_Exception();
				}

			}
	}



	/**
	 * ACL constructor
	 * @see http://framework.zend.com/manual/ru/zend.acl.html
	 * @return 
	 * @param object $acl[optional]
	 */
	static public function exportACL($acl = null)
	{
		if ((!is_object($acl)) || (empty($acl))) return false;
		else
		{
			//write your acl rule and define all
			//!INFO: Обязательно документируйте все свои роли и ресурсы, лучше всего с использованием префиксов
			
			// ниже сначала лучше всего описать все, что используется
			//список ролей и наследование (если есть)
			$_roles = array(); 
			
			//ресурсы
			$_resources = array();
			
			//действия, например edit, delete, view, add,
			$_actions = array('create', 'edit', 'view', 'delete');
			
			
			
			
			
			//Пример :)
			
			$acl->addRole(new Zend_Acl_Role('guest'))
			    ->addRole(new Zend_Acl_Role('member'))
			    ->addRole(new Zend_Acl_Role('admin'));
			
			$parents = array('guest', 'member', 'admin');
			$acl->addRole(new Zend_Acl_Role('someUser'), $parents);
			
			$acl->add(new Zend_Acl_Resource('someResource'));
			
			$acl->deny('guest', 'someResource');
			$acl->allow('member', 'someResource');
		}
	}
}